<?php echo $this->Html->css('/css/ui-lightness/jquery'); ?>
<div class="clients index">
	<h2><?php echo __('Clients'); ?></h2>

    <div id="search" style="text-align: left;">
        <?php
            echo $this->Form->create('Client',array('action' => 'index'));
            echo $this->Form->input('keyword', array('label' => 'Search for:'));

        ?>
    </div>

	<table cellpadding="0" cellspacing="0">
	<tr>
			<th><?php echo $this->Paginator->sort('id'); ?></th>
			<th><?php echo $this->Paginator->sort('surname'); ?></th>
			<th><?php echo $this->Paginator->sort('firstname'); ?></th>
			<th><?php echo $this->Paginator->sort('DOB'); ?></th>
			<th><?php echo $this->Paginator->sort('mobile_num'); ?></th>
			<th><?php echo $this->Paginator->sort('email'); ?></th>
			<th class="actions"><?php echo __('Actions'); ?></th>
	</tr>
	<?php foreach ($clients as $client): ?>
	<tr id="client_<?php echo h($client['Client']['id']);?>" class="client">
		<td><?php echo h($client['Client']['id']); ?>&nbsp;</td>
		<td><?php echo h($client['Client']['surname']); ?>&nbsp;</td>
		<td><?php echo h($client['Client']['firstname']); ?>&nbsp;</td>
		<td><?php echo h($client['Client']['DOB']); ?>&nbsp;</td>
		<td><?php echo h($client['Client']['mobile_num']); ?>&nbsp;</td>
		<td><?php echo h($client['Client']['email']); ?>&nbsp;</td>
		<td class="actions">
			<?php echo $this->Html->link(__('View'), array('action' => 'view', $client['Client']['id'])); ?>
			<?php echo $this->Html->link(__('Edit'), array('action' => 'edit', $client['Client']['id'])); ?>
			<?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $client['Client']['id']), null, __('Are you sure you want to delete # %s?', $client['Client']['id'])); ?>
		</td>
	</tr>
<?php endforeach; ?>
	</table>
	<p>
	<?php
	echo $this->Paginator->counter(array(
	'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
	));
	?>	</p>
	<div class="paging">
	<?php
		echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
		echo $this->Paginator->numbers(array('separator' => ''));
		echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
	?>
	</div>
</div>
<div id="TB_load"><?php echo $this->Html->image("loading_animation.gif")?></div>
<div class="actions">
	<h3><?php echo __('Actions'); ?></h3>
	<ul>
		<li><?php echo $this->Html->link(__('New Client'), array('action' => 'add')); ?></li>
	</ul>
</div>
<?php echo $this->Html->script('jquery.plugin'); ?>
<script type="text/javascript">
	$('#ClientKeyword').click(function(){$(this).attr('value','');});
	$('#ClientKeyword').blur(function(){$(this).attr('value',"Client name...");});
   	$( "#ClientKeyword" ).autocomplete({
		source: '<?php echo $webroot?>clients/search.json',
		delay: 10,
		autoFocus: false,
		minLength: 0,
		select: function(event, ui)
		{
			event.preventDefault();
			$("#ClientKeyword" ).val(ui.item.value);
			$('#ClientIndexForm').ajaxSubmit({target: "#main", beforeSubmit: salesBeforeSubmit, success: salesSuccess});
		},
		change: function(event, ui)
		{
			if ($(this).attr('value') != '' && $(this).attr('value') != "Client name...")
			{
				$("#ClientIndexForm").ajaxSubmit({target: "#main", beforeSubmit: salesBeforeSubmit, success: salesSuccess});
			}
			$(this).attr('value',"Client name...");
		}
	});
   	function salesBeforeSubmit(formData, jqForm, options)
   	{
   		$("#TB_load").show();//loading图片
   	}

   	function salesSuccess(responseText, statusText, xhr, $form)
   	{
   	}
</script>